import unittest
from parameterized import parameterized
import requests


def readFiles():
    f = open('02学生分页查询.txt', mode='r', encoding='utf-8')
    datas = f.readlines()
    r = [tuple(i.split(',')) for i in datas]
    return r

class XZS_fecx(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.session = requests.Session()
        a = {
            "userName": 'admin',
            "password": 123456,
            "remember": False
        }
        cls.session.post("http://localhost:8000/api/user/login", json=a)

    @classmethod
    def tearDownClass(cls):
        cls.session.close()

    @parameterized.expand((readFiles()))
    def test_student_pagination(self, userName, role, pageIndex, pageSize,code):
        a = {
            "userName": userName,
            "role": role,
            "pageIndex": pageIndex,
            "pageSize": pageSize
        }
        print(a)
        # 发送POST请求进行学生分页查询操作
        response = self.session.post("http://localhost:8000/api/admin/user/page/list", json=a)

        self.assertEqual(200, response.status_code)  # 断言响应状态码为200
        self.assertEqual(int(code), response.json()['code'])  # 断言返回参数中的code为1，表示成功

        # 多参
    def test_duocan(self):
        a = {
            "userName": "admin",
            "role": 1,
            "pageIndex": 1,
            "pageSize": 10,
            "msg":"123"
        }
        print(a)
        # 发送POST请求进行学生分页查询操作
        response = self.session.post("http://localhost:8000/api/admin/user/page/list", json=a)

        self.assertEqual(200, response.status_code)  # 断言响应状态码为200
        self.assertEqual(500, response.json()['code'])  # 断言返回参数中的code为1，表示成功


